package com.banmao.algorithm.No1To100.No3_Longest_Substring_Without_Repeating_Characters;

/**
 *  暴力破解
 *  超出LeetCode时间限制，未通过
 */
class Solution02 {
    static int lengthOfLongestSubstring(String s) {
        int max = 0;
        for(int i=0; i<s.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for(int j=i; j<s.length(); j++) {
                sb.append(s.charAt(j));
                if(judgeRepeat(sb) && max<sb.length()) {
                    max = sb.length();
                }
            }
        }
        return max;
    }

    private static boolean judgeRepeat(StringBuilder sb) {
        if(sb.length() == 1) {
            return true;
        }
        for(int i=0; i<sb.length()-1; i++) {
            for(int j=i+1; j<sb.length(); j++) {
                if(sb.charAt(i) == sb.charAt(j)) {
                    return false;
                }
            }
        }
        return true;
    }
}
